package com.china08.yxyapi.repository.db;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import com.china08.yxyapi.entity.db.lessons.YxyLessonsTopicLessonItem;

public interface YxyLessonsTopicLessonItemRepository extends JpaRepository<YxyLessonsTopicLessonItem, String> {
    @Query(value = " select t1 from YxyLessonsTopicLessonItem t1 where t1.lessonId = ?1 and t1.status = ?2 order by t1.createdDate desc")
    List<YxyLessonsTopicLessonItem> findLessonItemsrByLessonId(String lessonId, Integer status);

    YxyLessonsTopicLessonItem findById(String id);

    List<YxyLessonsTopicLessonItem> findByChapterId(String chapterId);

    List<YxyLessonsTopicLessonItem> findByChapterIdAndStatusNot(String chapterId, Integer status);

    YxyLessonsTopicLessonItem findTop1ByOrderNumLessThanOrderByOrderNumDesc(Integer orderNum);

    YxyLessonsTopicLessonItem findTop1ByOrderNumGreaterThanOrderByOrderNumAsc(Integer orderNum);

    Integer countByLessonIdIn(List<String> idOnes2);

    List<YxyLessonsTopicLessonItem> findByLessonId(String lessonId);

    Integer countByChapterId(String chapter);

    Integer countByLessonId(String lessonId);

    Integer countByLessonIdAndIdIn(String lessonId, List<String> itemsIds);

    @Query(value = " select max(t1.orderNum)  from YxyLessonsTopicLessonItem t1 where t1.chapterId = ?1")
    Integer findMaxOrderNumLessonItemByLessonId(String chapterId);

    @Query(value = " select t1 from YxyLessonsTopicLessonItem t1 where t1.lessonId = ?1 and t1.chapterId = ?2 and t1.videoId = ?3 and t1.status = ?4 order by t1.createdDate desc")
    List<YxyLessonsTopicLessonItem> findYxyItemByLessonIdAndChapterIdAndVideoId(String lessonId, String chapterId,
            String video, Integer status);

    YxyLessonsTopicLessonItem findTop1ByLessonIdAndStatusNotAndOrderNumLessThanOrderByOrderNumDesc(String lessonId,
            Integer status, Integer itemOrderNum);

    YxyLessonsTopicLessonItem findTop1ByLessonIdAndStatusNotAndOrderNumGreaterThanOrderByOrderNumAsc(String lessonId,
            Integer status, Integer itemOrderNum);

    List<YxyLessonsTopicLessonItem> findByChapterIdAndStatusNotOrderByOrderNum(String chapterId, Integer status);

    YxyLessonsTopicLessonItem findTop1ByLessonIdAndOrderNumLessThanAndStatusNotOrderByOrderNumDesc(String lessonId,
            Integer itemOrderNum, int i);

    YxyLessonsTopicLessonItem findTop1ByLessonIdAndOrderNumGreaterThanAndStatusNotOrderByOrderNumAsc(String lessonId,
            Integer itemOrderNum, int i);

    YxyLessonsTopicLessonItem findTop1ByChapterIdAndOrderNumLessThanAndStatusNotOrderByOrderNumDesc(String chapterId,
            Integer itemOrderNum, int i);

    YxyLessonsTopicLessonItem findTop1ByChapterIdAndOrderNumGreaterThanAndStatusNotOrderByOrderNumAsc(String chapterId,
            Integer itemOrderNum, int i);

    List<YxyLessonsTopicLessonItem> findByChapterIdAndStatusNotOrderByOrderNumAsc(String id, int i);

}
